<?php

/*
 * @license
 */

/**
 *
 * @author Jackson
 */
class SCCoreHelper {

    private static $_JSStructClassNameCache;

    public static function getJSStructClassName(IJSStruct $struct) {
        if (self::$_JSStructClassNameCache === null) {
            self::$_JSStructClassNameCache = SCCacheHelper::getInstance()->getObject('SCCoreHelper_JSStructClassNameCache');
            if (!is_array(self::$_JSStructClassNameCache))
                self::$_JSStructClassNameCache = array();
        }
        if (!key_exists($c = get_class($struct), self::$_JSStructClassNameCache) || IS_DEV) {
            $ref = $struct->getRefClass();
            self::$_JSStructClassNameCache[$c] = null;
            while ($ref != null) {
                $fileName = sCore::getRefClassFileName($ref);
                if (file_exists($filename = dirname($fileName) . "/{$ref->getName()}.js")) {
                    self::$_JSStructClassNameCache[$c] = substr($n = $ref->getName(), 0, 2) == 'SC' ? substr($n, 2) : $n;
                    break;
                }
                $ref = $ref->getParentClass();
            }
            SCCacheHelper::getInstance()->setObject('SCCoreHelper_JSStructClassNameCache', self::$_JSStructClassNameCache);
        }
        return self::$_JSStructClassNameCache[$c];
    }

    /**
     *
     * @param ReflectionClass $refClass
     * @param string $interface 
     * @return bool
     */
    public static function ImplementsInterfaceRecursively($refClass, $interface) {
        while ($refClass != null) {
            if ($refClass->implementsInterface($interface))
                return true;
            $refClass = $refClass->getParentClass();
        }
        return false;
    }

}

?>
